package Principal;

import Parser.ClasificadorEtiqueta;
import java.awt.Color;
import java.awt.event.KeyEvent;

public class Modifica extends javax.swing.JDialog {
  Principal principal = null;

    /** Creates new form Modifica */
    public Modifica(java.awt.Frame parent, boolean modal, String stCadena) {
        super(parent, modal);
        initComponents();
        principal = (Principal)parent;
        jtCadena.setText(stCadena);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jtCadena = new javax.swing.JTextField();
        jbtAceptar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);

        jtCadena.setFont(new java.awt.Font("Verdana", 0, 14));
        jtCadena.setPreferredSize(new java.awt.Dimension(6, 30));
        jtCadena.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jtCadenaKeyPressed(evt);
            }
        });

        jbtAceptar.setFont(new java.awt.Font("Verdana", 0, 14));
        jbtAceptar.setText("Aceptar");
        jbtAceptar.setMaximumSize(new java.awt.Dimension(87, 30));
        jbtAceptar.setMinimumSize(new java.awt.Dimension(87, 30));
        jbtAceptar.setPreferredSize(new java.awt.Dimension(87, 30));
        jbtAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtAceptarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jtCadena, javax.swing.GroupLayout.PREFERRED_SIZE, 365, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtAceptar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jtCadena, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbtAceptar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbtAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtAceptarActionPerformed
      // TODO add your handling code here:
     principal.CrearNodo(jtCadena.getText());
     this.dispose();
    }//GEN-LAST:event_jbtAceptarActionPerformed

    private void jtCadenaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtCadenaKeyPressed
      ClasificadorEtiqueta clas = new ClasificadorEtiqueta();
      if (evt.getKeyCode() == KeyEvent.VK_ENTER){
        if (clas.clasificar(jtCadena.getText()) == -1){
           jtCadena.setForeground(Color.RED);
        }
        else{
           jtCadena.setForeground(Color.GREEN);
        }
      }
      else{
        if (jtCadena.getForeground() != Color.BLACK){
          jtCadena.setForeground(Color.BLACK);
        }
      }
    }//GEN-LAST:event_jtCadenaKeyPressed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jbtAceptar;
    private javax.swing.JTextField jtCadena;
    // End of variables declaration//GEN-END:variables
}
